package cz.data.common.support.metadata;

import cz.data.common.support.DataTypeEnum;

public enum PostgresqlDataTypeEnum implements DataTypeEnum {

    VARCHAR("varchar", "变长字符串"),
    TEXT("text", "文本字符串"),
    SMALLINT("smallint", "smallint整型"),
    INTEGER("integer", "int整型"),
    BIGINT("bigint", "bigint整型"),
    NUMERIC("numeric", "numeric变长小数"),
    CHAR("char", "定长字符串"),
    DATE("date", "日期"),
    TIME("time", "时间"),
    DATETIME("datetime", "日期时间"),
    TIMESTAMP("timestamp", "日期时间戳"),
    BOOLEAN("boolean", "布尔"),
    JSON("json", "JSON"),
    BYTEA("bytea", "变长二进制"),
    ARRAY_VARCHAR("_varchar", "字符串数组")
    ;

    private final String value;
    private final String title;

    PostgresqlDataTypeEnum(String value, String title) {
        this.value = value;
        this.title = title;
    }

    public String getValue() {
        return value;
    }

    public String getTitle() {
        return title;
    }

    public static PostgresqlDataTypeEnum match(String value) {
        return match(value, VARCHAR);
    }

    public static PostgresqlDataTypeEnum match(String value, PostgresqlDataTypeEnum defaultItem) {
        if (value != null) {
            for (PostgresqlDataTypeEnum item: PostgresqlDataTypeEnum.values()) {
                if (item.getValue().equalsIgnoreCase(value)) {
                    return item;
                }
            }
        }
        return defaultItem;
    }
}
